package com.help10000.rms.mvp.presenter

import com.amir.common.api.CustomObserver
import com.amir.common.beans.GatheringCodeEntity
import com.amir.common.beans.PayResultEntity
import com.amir.common.mvp.model.Model
import com.amir.common.mvp.presenter.BasePresenter
import com.amir.common.utils.Constant
import com.amir.common.utils.SPUtils
import com.help10000.rms.mvp.view.GatheringCodeView

class GatheringCodePresenter(view: GatheringCodeView) : BasePresenter<GatheringCodeView>(view) {


    /**
     * 收款码
     */
    fun gathingCode(repairId: String?, ServCharge: Float) {

        val AccessToken = SPUtils.getString(Constant.AccessToken)
        val weixinNative = Model.getServer().WeixinNative(AccessToken, repairId, ServCharge)
        Model.getObservable(weixinNative, object : CustomObserver<GatheringCodeEntity>(mvpView) {

            override fun success(t: GatheringCodeEntity) {
                mvpView?.codeSuccess(t.data)
            }
        })
    }

    /**
     * 检查支付结果
     */
    fun checkPayResult(orderId: String?) {
        val AccessToken = SPUtils.getString(Constant.AccessToken)
        val weixinNative =
            Model.getServer().PayResult(AccessToken, orderId)
        Model.getObservable(weixinNative, object : CustomObserver<PayResultEntity>(mvpView) {

            override fun success(t: PayResultEntity) {
                mvpView?.payResult(t.data)
            }
        })
    }

}